﻿using Common.Util;
using Common.Contract;
using Common.Contract.Warranty.Request;
using Common.Contract.Warranty.Response;
using Common.Service.Command;
using Warranty.Model.Interface;
using Warranty.Model.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Warranty.ServiceCommand
{
    public class UpdateResponseSMSServiceCommand : ProviderServiceCommand<IResponseSMSProvider, UpdateResponseSMSRequest, ResponseRecord>
    {
        public UpdateResponseSMSServiceCommand(IResponseSMSProvider providers) : base(providers) { }

        protected override void Validate(UpdateResponseSMSRequest request)
        {
            if (request == null) throw new ArgumentNullException("request");
            if (!request.Header.ApplicationKey.HasValue || request.Header.ApplicationKey == Guid.Empty)
            {
                throw new ArgumentException("ApplicationKey must be set", "request");
            }
            if (request.Record == null)
            {
                throw new ArgumentException("Record must be set", "request");
            }
           
        }

        protected override bool OnExecute(ResponseRecord response)
        {
            var responseSMSRecord = Request.Record;
            var obj = new ResponseSMS()
            {
                GabitId =responseSMSRecord.GabitId,
                GabitTemplate = responseSMSRecord.GabitTemplate,
                MsgBodyLen = responseSMSRecord.MsgBodyLen,
                Purpose = responseSMSRecord.Purpose,
                RespMsg1 = responseSMSRecord.RespMsg1,
                RespMsg2 = responseSMSRecord.RespMsg2,
                RespType = responseSMSRecord.RespType,
                Template = responseSMSRecord.Template,
                SoTransferFlag = responseSMSRecord.TransferFlag.HasValue ? responseSMSRecord.TransferFlag.Value.ToBooleanString() : BooleanString.FALSE,
            };
            return Providers.Update(obj);
        }
    }
}
